// mcp-mysql-server.js
import { createServer } from "@modelcontext/server";
import mysql from "mysql2/promise";

const pool = mysql.createPool({
    host: "localhost",  // 改成你的 MySQL 地址
    user: "root",
    password: "fxjava",
    database: "anr_learning_machine"
});

const server = createServer({
    name: "mysql-mcp",
    version: "0.1.0",
    tools: {
        query: {
            description: "执行 SQL 查询",
            inputSchema: {
                type: "object",
                properties: {
                    sql: { type: "string" }
                },
                required: ["sql"]
            },
            async handler({ sql }) {
                const [rows] = await pool.query(sql);
                return { rows };
            }
        }
    }
});

server.start();
